import Vue from "vue";
import Vuex from "vuex";
import axios from "axios";
import { Message } from "element-ui";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    professionTypes: [
      {
        value: "writer",
        text: "作家",
        index: 0,
      },
    ],
    dealStates: [
      {
        value: "willing",
        text: "未交易",
        index: 0,
      },
    ],
  },
  mutations: {
    updateProfessionTypes(state, payload) {
      state.professionTypes = payload;
    },
    updateDealStates(state,payload){
      state.dealStates=payload;
    }
  },
  actions: {
    getProfessionTypes(context) {
      //this.$http  this.$message
      axios({
        method: "get",
        url: "/ceto/common/professionTypes",
      }).then(
        (res) => {
          Message.warning(JSON.stringify(res.data));
          context.commit("updateProfessionTypes", res.data);
        },
        (error) => {
          console.log(" request error : " + error.response.status);
        }
      );
    },
    getDealStates({ commit }){
      axios({
        method: "get",
        url: "ceto/common/dealStates",
      }).then(
        (res) => {
          Message.warning(JSON.stringify(res.data));
          commit("updateDealStates",res.data);
        },
        (error) => {
          console.log(" request error : "+error.response.status);
        }
      );
    }
  },
  modules: {},
});
